package com.it.od.od2024.od20240306;

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: liminghui
 * @date: 2024/3/5 23:03
 * @version: 1.0
 * @description:
 * 长方形停车场开启监控器
 * 某长方形停车场，每个车位上方都有对应监控器，当且仅当在当前车位或者前后左右四个方向任意一个车位范围停车时，监控器才需要打开；
 * 给出某一时刻停车场的停车分布，请统计最少需要打开多少个监控器；
 * 用例1:
 * 3 3
 * 0 0 0
 * 0 1 0
 * 0 0 0
 * 输出5
 */
public class Main2 {
    public static int[][] pos = {{0, 0}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int[] line = Arrays.stream(sc.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
        int n = line[0];
        int m = line[1];
        int[][] grid = new int[n][m];
        for (int i = 0; i < n; i++) {
            grid[i] = Arrays.stream(sc.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
        }

        int[][] visited = new int[n][m];
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) {
                    for (int k = 0; k < pos.length; k++) {
                        int x = i + pos[k][0];
                        int y = j + pos[k][1];
                        if (x < 0 || x > grid.length - 1 || y < 0 || y > grid[0].length - 1) {
                            continue;
                        }
                        visited[x][y] = 1;
                    }
                }

            }
        }

        int sum = 0;
        for (int i = 0; i < visited.length; i++) {
            for (int j = 0; j < visited[0].length; j++) {
                if (visited[i][j] == 1) {
                    sum += 1;
                }
            }
        }
        System.out.println(sum);


    }
}
